package com.scf.loanmanage.controller;

import com.scf.loanmanage.entity.OverDueCollection;
import com.scf.loanmanage.entity.PageBean;
import com.scf.loanmanage.service.OverDueCollectionService;
import com.scf.loanmanage.service.ServiceImp.AssetPreservationImpl;
import com.scf.uitl.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController

@RequestMapping("/OverDueCollection")
public class OverDueCollectionController {

    @Resource
    AssetPreservationImpl assetPreservation;

    @Resource
    OverDueCollectionService overDueCollectionService;


    @GetMapping("/repaymentAll")
    public ResponseResult selectAll(Integer pageIndex, Integer pageSize) {
        List<OverDueCollection> repayments = overDueCollectionService.selectAll(pageIndex,pageSize);
        Integer selectcount = overDueCollectionService.selectcount();
        System.out.println("一共："+selectcount);
        ResponseResult resposeResult=new ResponseResult();
        resposeResult.setCode(200);
        PageBean<OverDueCollection> pageBean=new PageBean<>();
        pageBean.setBeanList(repayments);
        pageBean.setPageBegin(pageIndex);
        pageBean.setPageEnd(pageSize);
        pageBean.setTotalRecord(selectcount);
        resposeResult.setData(pageBean);
        return resposeResult;
    }

    @GetMapping("/selcetByname")
    public ResponseResult selectByname(String enterprisename,String code) {
        List<OverDueCollection> repayments = overDueCollectionService.selectByname(enterprisename, code);
        ResponseResult resposeResult=new ResponseResult();
        resposeResult.setCode(200);
        resposeResult.setData(repayments);
        return resposeResult;
    }
    @GetMapping("/insert")
    public void insetByname(Integer oids) {
        OverDueCollection overDueCollection = overDueCollectionService.selctByid(oids);
        assetPreservation.insert(null, overDueCollection.getEnterprisename(), overDueCollection.getCode(), overDueCollection.getOverdueamount(), "张三", null, overDueCollection.getOverterm(), overDueCollection.getOverdate(), new Date());
    }
}
